﻿// AUTOMATICALLY GENERATED CODE

using System;
using System.IO;
using System.Collections.Generic;
using Sce.PlayStation.Core;
using Sce.PlayStation.Core.Imaging;
using Sce.PlayStation.Core.Environment;
using Sce.PlayStation.HighLevel.UI;

namespace VitaReaderLibPS
{
	
	public enum UISwitch
	{
		NONE,
		ZOOM,
		LEFT,
		RIGHT,
	};
	
    partial class ReaderScene
    {
		////background
		ImageBox	UIImgBk;

        private void InitializeWidget()
        {
			// UIImgBk
            UIImgBk = new ImageBox();
            UIImgBk.Name = "UIImgBk";
            UIImgBk.Image = mBackground;
			this.RootWidget.AddChildLast(UIImgBk);
			
			
			mUIList = new List<ReaderUI>();
			//reserve items
			for(int i = 0; i < ReaderUI.UI_COUNT; ++i)
			{
				mUIList.Add(null);
			}
			
			//create items
			
			//main menu
			MainMeu mainmenu = new MainMeu();
			mUIList[ (int)UIType.MAINMENU ] = mainmenu;
			
			//booklist
			BookList booklist = new BookList();
			mUIList[ (int)UIType.BOOKS ] = booklist;
			
			//bookmark
			BookMark bookmark = new BookMark();
			mUIList[ (int)UIType.BOOKMARKS ] = bookmark;
			
			//download
			Download download = new Download();
			mUIList[ (int)UIType.DOWNLOADS ] = download;
			
			//reading
			Reading reading = new Reading();
			mUIList[ (int)UIType.READING ] = reading;
			
			//init
			for(int i = 0; i < ReaderUI.UI_COUNT; ++i)
			{
				ReaderUI ui = mUIList[i];
				if( ui != null )
				{
					ui.Initialize(this);
					ui.RootWidget.Visible = false;
					
					if( ui as IReadingHandler != null )
						mReadingHandler = ui as IReadingHandler;
					
					this.RootWidget.AddChildLast(ui.RootWidget);
				}
			}
        }
		
		public void ShowUI(UIType type, UISwitch effect = UISwitch.NONE)
		{
			int index = (int)type;
			
			
			Effect In = null;
			Effect Out = null;
			const float EFFECT_TIME = 200;
			if( effect == UISwitch.LEFT  )
			{
				SlideInEffect effIn = new SlideInEffect();
				effIn.MoveDirection = FourWayDirection.Right;
				effIn.Time = EFFECT_TIME;
				In = effIn;
				
				SlideOutEffect effOut = new SlideOutEffect();
				effOut.MoveDirection = FourWayDirection.Right;
				effOut.Time = EFFECT_TIME;
				Out = effOut;
			}
			else if( effect == UISwitch.RIGHT )
			{
				SlideInEffect effIn = new SlideInEffect();
				effIn.MoveDirection = FourWayDirection.Left;
				effIn.Time = EFFECT_TIME;
				In = effIn;
				
				SlideOutEffect effOut = new SlideOutEffect();
				effOut.MoveDirection = FourWayDirection.Left;
				effOut.Time = EFFECT_TIME;
				Out = effOut;
			}
			else if( effect == UISwitch.ZOOM )
			{
				ZoomEffect effIn = new ZoomEffect();
				effIn.TargetScaleX = 1;
				effIn.TargetScaleY = 1;
				effIn.TargetScaleZ = 1;
				effIn.Time = EFFECT_TIME;
				In = effIn;
				
				/*
				SlideOutEffect effOut = new SlideOutEffect();
				effOut.MoveDirection = FourWayDirection.Left;
				effOut.Time = 300;
				Out = effOut;
				*/
			}
			
			for(int i = 0; i < ReaderUI.UI_COUNT; ++i)
			{
				ReaderUI ui = mUIList[i];
				if( ui == null ) //un-implemented
					continue;
				
				if( i == index )
				{
					//ui.GetRoot().Show(In);
					
					if( !ui.Visible )
					{
						ui.Show(In);
					}
				}
				else
				{
					//ui.GetRoot().SetFocus(false);
					
					if( ui.Visible)
					{
						ui.Hide(Out);
					}
				}
			}
		}
		
		private void UpdateLanguage()
		{
			this.Title = "VitaBookReader";
			
			String lang = mView.Owner.GetSystemLanguage();
			
			StreamReader reader = new StreamReader( "/Application/lang/" + lang + ".txt");
			
			mLang.UpdateLanguage(reader);
		
			for(int i = 0; i < ReaderUI.UI_COUNT; ++i)
			{
				ReaderUI ui = mUIList[i];
				if( ui != null )
					ui.UpdateLanguage(reader);
			}
		}
		
		#region layouts
        private LayoutOrientation _currentLayoutOrientation;
		public LayoutOrientation Layout
		{
			get { return _currentLayoutOrientation;}
		}
			
        private void SetWidgetLayout(LayoutOrientation orientation)
        {
            _currentLayoutOrientation = orientation;
			
			switch (orientation)
            {
            case LayoutOrientation.Vertical:
                this.DesignWidth = mView.Height;
                this.DesignHeight = mView.Width;

				//back ground
				UIImgBk.SetPosition(0, 0);
                UIImgBk.SetSize(mView.Width, mView.Height);
                UIImgBk.Anchors = Anchors.Top | Anchors.Height | Anchors.Left | Anchors.Width;
                UIImgBk.Visible = true;
				
				break;
            default:
				this.DesignWidth = mView.Width;
				this.DesignHeight = mView.Height;
				
				//back ground
				UIImgBk.SetPosition(0, 0);
                UIImgBk.SetSize(mView.Width, mView.Height);
                UIImgBk.Anchors = Anchors.Top | Anchors.Height | Anchors.Left | Anchors.Width;
                UIImgBk.Visible = true;
				break;
            }//switch
		
			for(int i = 0; i < ReaderUI.UI_COUNT; ++i)
			{
				ReaderUI ui = mUIList[i];
				if( ui != null )
					ui.UpdateLayout(orientation);
			}
        }

        private void onShowing(object sender, EventArgs e)
        {
            switch (_currentLayoutOrientation)
            {
                case LayoutOrientation.Vertical:
                {
                }
                break;

                default:
                {
                }
                break;
            }
        }
        private void onShown(object sender, EventArgs e)
        {
            switch (_currentLayoutOrientation)
            {
                case LayoutOrientation.Vertical:
                {
                }
                break;

                default:
                {
                }
                break;
            }
        }
		#endregion
    }
}
